﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FSS;
using System;

public class BuidingTypeConfigMgr : Singleton<BuidingTypeConfigMgr>
{
    public BuidingTypeConfig mConfig = new BuidingTypeConfig();
    public void LoadFromFile(string filename)
    {
        mConfig.mListData = new List<BuidingTypeElement>();
        CSVHelper.Instance().ReadCSVFile(filename, (table) =>
        {
            foreach (CSVLine line in table)
            {
                BuidingTypeElement bte = ParseLine(line);
                mConfig.mListData.Add(bte);
            }
        });
    }

    BuidingTypeElement ParseLine(CSVLine line)
    {
        BuidingTypeElement bte = new BuidingTypeElement();
        foreach(KeyValuePair<string,string> item in line)
        {
            switch(item.Key)
            {
                case "id":
                    bte.id = Convert.ToInt32(item.Value);
                    break;
                case "name":
                    bte.name = item.Value;
                    break;
                case "desc":
                    bte.desc = item.Value;
                    break;
                default:
                    break;
            }
        }
        return bte;
    }
}

public class BuidingTypeElement
{
    public int id;
    public string name;
    public string desc;
}

public class BuidingTypeConfig
{
    public List<BuidingTypeElement> mListData;
}
